package org.example.design.factory.itf.impl;

import cn.hutool.json.JSONUtil;
import org.example.design.factory.goods.DeliverReq;
import org.example.design.factory.goods.GoodsService;
import org.example.design.factory.itf.Commodity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

/**
 * @Classname GoodCommdityServie
 * @Description T
 * @Date 2020/10/30 11:11 上午
 * @Created by xiangjd
 */
public class GoodCommdityServie implements Commodity {
    private Logger logger = LoggerFactory.getLogger(GoodCommdityServie.class);

    private GoodsService goodsService = new GoodsService();

    @Override
    public void SendCommidIty(String userId, String commId, String bizId, Map<String, String> extMap) throws Exception {
        DeliverReq deliverReq = new DeliverReq();
        deliverReq.setUserName(queryUserName(userId));
        deliverReq.setUserPhone(queryUserPhoneNumber(userId));
        deliverReq.setSku(commId);
        deliverReq.setOrderId(bizId);
        deliverReq.setConsigneeUserName(extMap.get("consigneeUserName"));
        deliverReq.setConsigneeUserPhone(extMap.get("consigneeUserPhone"));
        deliverReq.setConsigneeUserAddress(extMap.get("consigneeUserAddress"));

        Boolean aBoolean = goodsService.deliverGoods(deliverReq);
        logger.info("请求参数【实物】=====: uid:{},commId:{}, bizId:{},extMap:{}", userId, commId, bizId, JSONUtil.toJsonStr(extMap));
        logger.info("测试结果【实物】=====：{}", aBoolean);

        if (!aBoolean) {
            throw new RuntimeException("实物商品发放失败");
        }
    }


    private String queryUserName(String uId) {
        return "花花";
    }

    private String queryUserPhoneNumber(String uId) {
        return "15200101232";
    }
}
